package maosy.oauth2.server.test.spring.repository

import maosy.oauth2.server.inline.password
import maosy.oauth2.server.inline.uuid
import maosy.oauth2.server.jpa.bean.TbUserEntity
import maosy.oauth2.server.jpa.repository.UserRepository
import maosy.oauth2.server.test.spring.SpringTest
import org.junit.Assert
import org.junit.Test
import org.springframework.beans.factory.annotation.Autowired
import java.util.*


class UserRepositoryTest : SpringTest() {

    @Autowired
    lateinit var userRepository: UserRepository

    @Test
    fun test() {
        Assert.assertNotNull(userRepository)
    }

    @Test
    fun saveTest() {
        val result = userRepository.save(TbUserEntity().apply {
            id = String.uuid()
            userName = "admin"
            password = String.password("111111")
            createTime = Date()
            userState = 1
        })
        println(result)
    }

    @Test
    fun queryTest() {
        val entity = userRepository.queryByUserName<TbUserEntity>("admin")
        println(entity)
    }

    @Test
    fun countTest() {
        val count = userRepository.count()
        println(count)
        Assert.assertNotNull(count)
    }

}